﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Pku.BookStore.Web.Controllers
{
    public class ManageAuthorizeAttribute : AuthorizeAttribute
    {
        /// <summary>
        /// 判断用户是否登录
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            HttpContextBase context = filterContext.HttpContext;
            var strActionName = filterContext.RouteData.Values.Values.ToList()[1].ToString();
            if (context.Session["EmployeeID"] == null && strActionName != "LogOn")
            {
                filterContext.Result = new RedirectResult("/Admin/LogOn");
                return;
            }
        }
    }

    public class UserAuthorizeAttribute : AuthorizeAttribute
    {
        /// <summary>
        /// 判断用户是否登录
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            HttpContextBase context = filterContext.HttpContext;
            var strActionName = filterContext.RouteData.Values.Values.ToList()[1].ToString();
            if (context.Session["UserID"] == null && strActionName != "LogOn" && strActionName != "Reg")
            {
                filterContext.Result = new RedirectResult("/User/LogOn");
                return;
            }
        }
    }
}